home *** CD-ROM | disk | FTP | other *** search
- class Ball
- {
- var holder;
- var x;
- var y;
- var type;
- var dx;
- var dy;
- var sht_val;
- var broadcastMessage;
- static var parentMC;
- static var holder_width;
- static var shootSpeed;
- static var sceneWidth;
- static var sceneHeight;
- static var timer;
- function Ball(mc, id, __x, __y, _type)
- {
- this.holder = Ball.parentMC.attachMovie(mc,"b" + id,id + 1000);
- this.holder.setMask(_root.center_mc.mask);
- this.x = __x;
- this.y = __y;
- this.holder._x = this.x;
- this.holder._y = this.y;
- this.holder._width = this.holder._height = Ball.holder_width;
- this.type = _type;
- this.holder.gotoAndStop(this.type);
- AsBroadcaster.initialize(this);
- }
- static function init(pMC, speed, width, height, ball_width, _timer)
- {
- Ball.parentMC = pMC;
- Ball.shootSpeed = speed;
- Ball.sceneWidth = width + Ball.shootSpeed;
- Ball.sceneHeight = height + Ball.shootSpeed;
- Ball.holder_width = ball_width;
- Ball.timer = _timer;
- }
- function shoot(x, y)
- {
- var _loc2_ = undefined;
- _loc2_ = Ball.shootSpeed / Math.sqrt(x * x + y * y);
- this.dx = x * _loc2_;
- this.dy = y * _loc2_;
- this.sht_val = setInterval(this,"shootStep",Ball.timer);
- }
- function shootStep()
- {
- this.x += this.dx;
- this.y += this.dy;
- if(this.outOfScene())
- {
- this.broadcastMessage("shootFinish",this);
- this.clearBall();
- }
- else
- {
- this.holder._x = this.x;
- this.holder._y = this.y;
- this.broadcastMessage("shootStep",this);
- }
- updateAfterEvent();
- }
- function clearBall()
- {
- clearInterval(this.sht_val);
- this.holder.removeMovieClip();
- false;
- }
- function moveStop()
- {
- clearInterval(this.sht_val);
- }
- function outOfScene()
- {
- return this.x < - Ball.shootSpeed || this.y < - Ball.shootSpeed || this.x > Ball.sceneWidth || this.y > Ball.sceneHeight;
- }
- }
-